<?php
class cache_all
{
    public function __construct() {
        $funcs = get_class_methods($this);
        foreach ($funcs as $f)
        {
            if(strpos($f, 'cache_')===false) continue;
            $this->$f();
        }
    }

    function cache_category()
    {
        cache_all_category();
    }
    //模型缓存
    function cache_model()
    {
        $classname = 'model';
        include_once "./include/$classname.class.php";
        $o = new $classname;

        $models = $o->listinfo();
        if(is_array($models))
        {
            foreach($models as $m)
            {
                $o->cache_model($m['id']);
            }
        }
    }

    //内容状态缓存
    function cache_status()
    {
        $classname = 'workflow';
        include_once "./include/$classname.class.php";
        $o = new $classname;
        $o->status_cache();
    }

    //模板缓存
    function cache_tpl_cache($cache_dir = TEMPLATE_CACHE_PATH)
    {
    	if (is_dir($cache_dir))
		{
		    if ($dh = opendir($cache_dir))
		    {
		        while (($file = readdir($dh)) !== false)
		        {
		        	if($file == '.' || $file == '..')
		        	{
		        		continue;
		        	}
		        	$res = stristr($file, '.tpl.php');
		            if(!empty($res) && file_exists($cache_dir . $file))
		            {
		            	unlink($cache_dir . $file);
		            }
		            else
		            {
		            	$res = stristr($file , 'svn');
		            	if(empty($res) && is_dir($cache_dir.$file))
		            	{
		            		$this->cache_tpl_cache($cache_dir.$file.'/');
		            	}
		            }
		        }
		        closedir($dh);
		    }
		}
    }

    //表结构缓存
    function cache_table_cache()
    {
    	global $db;
    	$db->clean_cache();
    }
}

?>
